;!function (win,layer)
{
	var $=win.jQuery||win.Zepto;
	if (typeof $ === 'undefined') {
        console.log('本插件需要jQuery或Zepto支持');
		return false;
    }
	else
	{
		if (typeof $.fn.zTree === 'undefined') {
			console.log('本插件需要zTree支持');
			return false;
		}
	}
	
	if (typeof layer === 'undefined') {
		console.log('本插件需要layer插件支持支持');
		return false;
	}

	//可配置参数
	var defaults={
		Width:0,
		Height:0,
		setting:{
			view: {
				showIcon: false
			},
			data: {
				simpleData: {
					enable: true,
					idKey: "id",
					pIdKey: "pId",
					rootPId: 0
				}
			},
			callback:
				{
					onCheck: function(event, treeId, treeNode)
					{
						
					},
					onClick: function(event, treeId, treeNode)
					{
						
					},
					beforeClick: function(event, treeId, treeNode)
					{
						
					}
				}
			
			},//ztree参数
		zNodes:[]//ztree的数据
		};
	
	
	
    //定义到JQ的函数名
	$.fn.LayerTree=function(option)
	{
		
		option=$.extend(true,{},defaults,option||{});//合并参数
		var $this=$(this);

		option.Width = option.Width || $this.outerWidth();
		option.Height = option.Height || 200; 
		option.top = (option.top || $this.offset().top)-$(win.document).scrollTop()+option.Height;
		option.left = option.left || $this.offset().left;

            var domid="xvlayertree"+Math.floor(Math.random()*1000000)
			layer.open({
			  title: false,
			  closeBtn: 0,
			  shadeClose:true,
			  anim:-1,
			  fixed: false,
			  resize:false,
			  area: [option.Width+"px","300px"],
			  offset: [option.top+"px", option.left+"px"],
			  content: '<div class="ztree" id="'+domid+'" ></div>',
			  success: function(layero, index){
		
					$.fn.zTree.init($("#"+domid), option.setting, option.zNodes);
		
			  }
			});     
		
		
		return this;//返回对象以便可以二次操作
	}
 //这里放入插件代码
}(window,layer);